﻿
Partial Class recover
    Inherits System.Web.UI.Page
    Dim u As MembershipUser
    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles ResetPasswordButton.Click
        Dim newPassword As String
        u = Membership.GetUser(UsernameTextBox.Text, False)

        If u Is Nothing Then
            Msg.Text = "Username " & Server.HtmlEncode(UsernameTextBox.Text) & " not found. Please check the value and re-enter."
            Return
        End If

        Try
            newPassword = u.ResetPassword()

        Catch ex As MembershipPasswordException
            msg.Text = "Invalid password answer. Please re-enter and try again."
            Return
        Catch ex As Exception
            msg.Text = ex.Message
            Return
        End Try

        If Not newPassword Is Nothing Then
            Msg.Text = "Password reset. Your new password is: " & Server.HtmlEncode(newPassword)
        Else
            Msg.Text = "Password reset failed. Please re-enter your values and try again."
        End If
    End Sub
    Public Sub VerifyUsername()
        u = Membership.GetUser(UsernameTextBox.Text, False)

        If u Is Nothing Then
            Msg.Text = "Username " & Server.HtmlEncode(UsernameTextBox.Text) & " not found. Please check the value and re-enter."

            ResetPasswordButton.Enabled = False
        Else
            ResetPasswordButton.Enabled = True
        End If
    End Sub

    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        If Not Membership.EnablePasswordReset Then
            FormsAuthentication.RedirectToLoginPage()
        End If
        msg.Text = ""

        If Not IsPostBack Then
            msg.Text = "Please supply a username."
        Else
            VerifyUsername()
        End If
    End Sub

    Protected Sub Page_LoadComplete(sender As Object, e As EventArgs) Handles Me.LoadComplete
        
    End Sub

    Protected Sub ResetPassword_OnClick(sender As Object, e As EventArgs) Handles ResetPasswordButton.Click

    End Sub
End Class
